// -*-c#-*-
// License: New BSD License : http://www.opensource.org/licenses/bsd-license.php
//
// Copyright (c) 2008, Brothers In Arms/Burl Nyswonger
//
// See: BiaVote.uc for full License
// 
//@L

class BiaVoteWelcomeScene extends UTUIFrontEnd;

/* ------------------------------------------------------------------------- */

`include( BiaVote/Classes/BiaStdInc.uci );
`include( BiaVote/Classes/BiaVote.uci );

/* ------------------------------------------------------------------------- */


var transient UILabel           lbl_message;
var transient UILabelButton     btn_ok;
var config array<string>        MessageText;

const MAXLINE = 61;             //TODO: gotta do this differently!
var string                      MsgTxt;

var BiaVoteDataStore            DS;

// experimenting with a "ticker..." - TODO: just use a UTTabPage instad, it has an OnTick() event.
//var array<string>               aTicker;
//var int                         TickerIndex;

event SceneActivated(bool bInitialActivation)
{
    `BiaEnter();
    

    lbl_message = UILabel(FindChild('lbl_message', true));    
    btn_ok = UILabelButton(FindChild('btn_ok', true));    

    set_lbl('BiaWelcomeTitle', "<BiaVoteDataStore:BiaWelcomeTitle>");
    set_lbl('lbl_biavote_info', "[BIA]Vote -- v" $ `BiaVoteVersion $ " -- http://code.google.com/p/ut3-sniper-game");

//ticker:
//    aTicker.Length = 0;
//    aTicker[aTicker.Length] = "[BIA]Vote -- v" $ `BiaVoteVersion $ " -- http://code.google.com/p/ut3-sniper-game";
//    aTicker[aTicker.Length] = "Visit BIA -- http://bia-2k4.com";


    lbl_message.SetDataStoreBinding( MsgTxt );
    btn_ok.OnClicked = OkClicked;

    btn_ok.SetDataStoreBinding("Play!");
    
    `BiaExit();
}

function set_lbl( name nm, string txt )
{
    local UILabel uil;
    uil = UILabel(FindChild(nm, true));
    if( uil != None )
    {
        uil.SetDataStoreBinding(txt);
    }
    else
    {
        `BiaDbg("Unable to set datastorebinding for " $ nm );
    }
}

event PostInitialize()
{
    local int i;
    local UIProviderScriptFieldValue U;
    local string line;
    
    Super.PostInitialize();
    
    `BiaDbg("Looking for datastore client...");
    
    DS = class'BiaVote.BiaVoteDataClient'.static.GetDs( GetUTPlayerOwner() );
    
    if( DS != None )
    {
        MsgTxt = "";
        
        for(i = 0; i < 20; i++)
        {
            `BiaDbg("Grabbing data at Index " $ i);
            if( DS.GetFieldValue("Message", U, i ) )
            {
                line = U.StringValue;
                if( Len(line) > MAXLINE )
                {
                    line = Left(Line, MAXLINE);
                }
                `BiaDbg("Got stuff: " $ line);
                MsgTxt $= line;
                MsgTxt $= "\n";
            }
            else
            {
                break;
            }
        }
    }
    else
    {
        `BiaError("Unable to find DataStoreClient!");
    }
}

/* ticker:
function MyTick( int t )
{
    if( t % 4 == 0 )
    {
        TickerIndex += 1;
        if(TickerIndex >= aTicker.Length)
        {
            TickerIndex = 0;
        }
        set_lbl('lbl_biavote_info', aTicker[TickerIndex]);
    }
}
*/


function SetupButtonBar()
{
    if(ButtonBar != None)
    {
        ButtonBar.Clear();
        ButtonBar.AppendButton("Play!", OnButtonbar_Back);
    }
}

function bool OnButtonbar_Back(UIScreenObject InButton, int InPlayerIndex)
{
    MyCloseScene();
    return true;
}

function MyCloseScene()
{
    CloseScene(self);
}

function bool OkClicked(UIScreenObject EventObject, int PlayerIndex)
{
    MyCloseScene();
    return true;
}


defaultproperties
{
}
